package com.android.fragmentdemo.fragments
import androidx.lifecycle.MutableLiveData
import com.hengfoxwolf.commonbase.base.BaseViewModel
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class FragmentsInteractionModel : BaseViewModel() {

    var number = MutableLiveData(0)

    private var job: Job? = null

    init {
        job = launch {
            while (true) {
                delay(1000)
                number.value = (number.value ?: 0) + 1
            }
        }
        job?.start()
    }

    override fun onCleared() {
        super.onCleared()
        job?.cancel()
    }
}